
// <copyright file="CallbackBasedDataReaderDecorator.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The can read callback.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Data
{
    using System.Data;

    #region Delegates

    /// <summary>
    /// The can read callback.
    /// </summary>
    /// <param name="reader">
    /// The reader.
    /// </param>
    public delegate bool CanReadCallback(IDataReader reader);

    #endregion Delegates

    /// <summary>
    /// The callback based data reader decorator.
    /// </summary>
    public sealed class CallbackBasedDataReaderDecorator : DataReaderDecorator
    {
        #region Fields

        /// <summary>
        /// The can read callback.
        /// </summary>
        private readonly CanReadCallback _canReadCallback;

        #endregion Fields

        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="CallbackBasedDataReaderDecorator"/> class.
        /// </summary>
        /// <param name="adaptedObject">
        /// The adaptedObject.
        /// </param>
        /// <param name="canReadCallback">
        /// The can read callback.
        /// </param>
        public CallbackBasedDataReaderDecorator(IDataReader adaptedObject, CanReadCallback canReadCallback)
            : base(adaptedObject)
        {
            this._canReadCallback = canReadCallback;
        }

        #endregion Constructors and Finalizers

        #region Methods

        /// <summary>
        /// The read protected.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected override bool readProtected()
        {
            return this._canReadCallback(this);
        }

        #endregion Methods
    }
}